﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Text;

namespace Shop.Common
{
    public class HandleHttp
    {
        #region 通用GET方法
        public static string Get(string Url, string postDataStr)
        {
            string sUrl = Url + postDataStr;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sUrl);
            request.Method = "GET";
            //request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string strReturn = "";
            using (Stream myResponseStream = response.GetResponseStream())
            {
                byte[] buf = new byte[1024];
                while (true)
                {
                    int len = myResponseStream.Read(buf, 0, buf.Length);
                    if (len <= 0)
                    { break; }
                    //strReturn += System.Text.Encoding.GetEncoding("GB2312").GetString(buf, 0, len);
                    byte[] b = System.Text.Encoding.Convert(System.Text.Encoding.Default, System.Text.Encoding.UTF8, buf);
                    strReturn += System.Text.Encoding.UTF8.GetString(b, 0, b.Length);
                    //strReturn += System.Text.Encoding.GetEncoding("utf-8").GetString(buf, 0, len);
                }
                //strReturn = new String(buf, 0, 1024, System.Text.Encoding.GetEncoding("utf-8"));

                //StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
                //StreamReader myStreamReader = new StreamReader(myResponseStream);
                //string retString = myStreamReader.ReadToEnd();
                //myStreamReader.Close();
                myResponseStream.Close();
            }
            return strReturn;
        }
        #endregion 
    }
}